<?php
namespace Admin\Controller;

use Util\AccessController;

/*
 * 有赞接口
 */

class LevelController extends AccessController {
    public function index() {
        $this->display();
    }

    public function handling() {
        $nums = $_POST['IDS'];
        $fs = 100;
        foreach ($nums as $k => $v) {
            $fs -= $v;
        }
        $cs = '';
        switch ($fs) {
            case $fs > 0 && $fs <= 10:
                $cs = '废纸';
                break;
            case $fs > 10 && $fs <= 20:
                $cs = '2成新';
                break;
            case $fs > 20 && $fs <= 30:
                $cs = '3成新';
                break;
            case $fs > 30 && $fs <= 40:
                $cs = '4成新';
                break;
            case $fs > 40 && $fs <= 50:
                $cs = '5成新';
                break;
            case $fs > 50 && $fs <= 60:
                $cs = '6成新';
                break;
            case $fs > 60 && $fs <= 70:
                $cs = '7成新';
                break;
            case $fs > 70 && $fs <= 80:
                $cs = '8成新';
                break;
            case $fs > 80 && $fs <= 90:
                $cs = '9成新';
                break;
            case $fs > 90 && $fs <= 95:
                $cs = '9.5成新';
                break;
            case $fs > 95 && $fs < 100:
                $cs = '9.9成新';
                break;
            case $fs == 100:
                $cs = '全新';
                break;
        }
        echo $cs;

    }

    public function qrhandling() {
        $where['ID'] = $_POST['ID'];
        $LS = Service('Level', 'book');
        $data = $LS->find($where);
        $BOOK_MONEY = C('BOOK_MONEY');
        $cs = $_POST['cs'];
        if ($data) {
            if($BOOK_MONEY[$data['PACKING_SPECIFICATION']]){
                if($BOOK_MONEY[$data['PACKING_SPECIFICATION']][$_POST['cs']]) {
                    $cost = $data['Y_PRICE'] * ($BOOK_MONEY[$data['PACKING_SPECIFICATION']][$_POST['cs']]);
                }else{
                    $cost = $data['Y_PRICE'];
                    $cs ='九成新以下';
                }
            }else{
                echo "请先维护书籍包装";
                die();
            }
            $save['LEVEL'] = $cs;
            $save['XS_PRICE'] = $cost;
            $OK = $LS->update($where, $save);
            echo $OK;
        } else {
            echo "数据错误";
        }
    }
}